package com.pengshun.modules.api.user.controller;

import com.pengshun.config.NoRepeatSubmit;
import com.pengshun.modules.api.coal.validator.*;
import com.pengshun.modules.api.order.service.dto.IncomeRecordDto;
import com.pengshun.modules.api.order.service.dto.MerchantOrderDto;
import com.pengshun.modules.api.user.para.RunningWaterPara;
import com.pengshun.modules.api.user.para.UserPara;
import com.pengshun.modules.api.user.para.WithdrawPara;
import com.pengshun.modules.api.user.service.AccountService;
import com.pengshun.modules.common.BaseResult;
import com.pengshun.modules.common.PagePara;
import com.pengshun.modules.domain.User;
import com.pengshun.modules.security.Authorization;
import com.pengshun.modules.security.CurrUserInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author luoligang
 * @create 2021/2/4
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "账户相关")
@RequestMapping("/api/user/account")
public class AccountController {

    private final AccountService accountService;


    @ApiOperation(value = "我的钱包")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "status", value = "0全部 1收入2支出", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "page", value = "当前页,", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "请求条数", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header"),
    })
    @GetMapping(value = "/wallet", produces = "application/json; charset=utf-8")
    @Authorization
    public BaseResult getWallet(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Fourth.class}) PagePara para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = accountService.getWallet(para);
        return res;
    }

    @ApiOperation(value = "我的账单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "status", value = "0全部 1充值2支出", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "page", value = "当前页,", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "请求条数", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header"),
    })
    @GetMapping(value = "/bill", produces = "application/json; charset=utf-8")
    @Authorization
    public BaseResult bill(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Fourth.class}) PagePara para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = accountService.bill(para);
        return res;
    }

    @ApiOperation(value = "加油累计")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header"),
    })
    @GetMapping(value = "/accruing-amounts", produces = "application/json; charset=utf-8")
    @Authorization
    public BaseResult accruingAmounts(@ApiIgnore @CurrUserInfo User user) throws Exception {
        BaseResult res = accountService.accruingAmounts(user.getId());
        return res;
    }
    @ApiOperation(value = "支付二维码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header"),
    })
    @GetMapping(value = "/pay-qrcode", produces = "application/json; charset=utf-8")
    @Authorization
    public BaseResult payQrcode(@ApiIgnore @CurrUserInfo User user) throws Exception {
        BaseResult res = accountService.payQrcode(user.getId());
        return res;
    }

    @ApiOperation(value = "余额查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header"),
    })
    @GetMapping(value = "/balance", produces = "application/json; charset=utf-8")
    @Authorization
    public BaseResult getBalance(@ApiIgnore @CurrUserInfo User user) throws Exception {
        BaseResult res = accountService.getBalance(user.getId());
        return res;
    }

    @ApiOperation(value = "流水")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "status", value = "1收入,2支出,", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "page", value = "当前页,", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "请求条数", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "date", value = "日期yyyy-MM-dd", dataType = "int",  paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header"),
    })
    @GetMapping(value = "/running-water", produces = "application/json; charset=utf-8")
    @Authorization
    public BaseResult getRunningWater(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {First.class}) RunningWaterPara para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = accountService.getRunningWater(para);
        return res;
    }
    @ApiOperation(value = "账单明细")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "incomeRecordId", value = "流水id,", dataType = "int", required = true, paramType = "query"),
    })
    @GetMapping(value = "/detil", produces = "application/json; charset=utf-8")
    @Authorization
    public BaseResult getRunningWaterDetil(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Second.class}) RunningWaterPara para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = accountService.getRunningWaterDetil(para);
        return res;
    }

    @ApiOperation(value = "充值")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "money", value = "充值金额 单位分 传整数 0.56 传56", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @PostMapping(value = "/pay", produces = "application/json; charset=utf-8")
    @Authorization
    public BaseResult pay(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {Second.class}) IncomeRecordDto para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = accountService.pay(para);
        return res;
    }

    @ApiOperation(value = "提现")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "money", value = "提现金额 最低1元", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "userBankId", value = "银行卡id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @PostMapping(value = "/withdraw", produces = "application/json; charset=utf-8")
    @Authorization
    @NoRepeatSubmit
    public BaseResult withdraw(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {First.class}) IncomeRecordDto para) throws Exception {
        para.setUserId(user.getId());
        BaseResult res = accountService.withdraw(para);
        return res;
    }
    @ApiOperation(value = "提现记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startDate", value = "开始日期", dataType = "string",  paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束日期", dataType = "string",  paramType = "query"),
            @ApiImplicitParam(name = "page", value = "当前页,", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "请求条数", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "jwtToken", value = "jwtToken", dataType = "string", required = true, paramType = "header")
    })
    @PostMapping(value = "/withdraw-record", produces = "application/json; charset=utf-8")
    @Authorization
    public BaseResult withdrawRecord(@ApiIgnore @CurrUserInfo User user,  @ApiIgnore @Validated(value = {First.class}) PagePara page, WithdrawPara para) throws Exception {
        BaseResult res = accountService.withdrawRecord(user.getId(),page,para);
        return res;
    }

}
